package net.alegen.android.pizzashop.ui.order;

import java.util.ArrayList;
import java.util.List;

import net.alegen.android.pizzashop.R;
import net.alegen.android.pizzashop.order.Order;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.Menu;

public class OrderActivity extends FragmentActivity {
	
	public static OrderActivity LastCreatedInstance = null;

    SectionsPagerAdapter sectionsPagerAdapter;
    ViewPager viewPager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    	LastCreatedInstance = this;    	
        super.onCreate(savedInstanceState);
        setContentView(R.layout.order_activity);

        sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
        viewPager = (ViewPager) findViewById(R.id.pager);
        viewPager.setAdapter(sectionsPagerAdapter);
        
        Order.newOrder();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.order_activity, menu);
        return true;
    }

    /**
     * Inner SectionsPagerAdapter class
     */
    public class SectionsPagerAdapter extends FragmentPagerAdapter {
    	
    	private List<Fragment> fragmentList;

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
            
            this.fragmentList = new ArrayList<Fragment>();
            this.fragmentList.add(new ShapeLayoutFragment());
            this.fragmentList.add(new CheeseLayoutFragment());
            this.fragmentList.add(new ToppingLayoutFragment());
            this.fragmentList.add(new ClientInfoLayoutFragment());
        }

        @Override
        public Fragment getItem(int i) {
        	return this.fragmentList.get(i);
        }

        @Override
        public int getCount() {
            return this.fragmentList.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0: return getString(R.string.title_shape).toUpperCase();
                case 1: return getString(R.string.title_cheese).toUpperCase();
                case 2: return getString(R.string.title_topping).toUpperCase();
                case 3: return getString(R.string.title_client_info).toUpperCase();
            }
            return null;
        }
    }    
}
